import { ref, provide, watchEffect } from 'vue'
import { RouteLocationNormalizedLoaded } from 'vue-router'

// 设置layout菜单显隐变量
export function setLayoutProvide (route: RouteLocationNormalizedLoaded) {
  const showNavBar = ref(true)
  const triggerShowNavBar = (state?: boolean) => {
    showNavBar.value = typeof state === 'undefined' ? !showNavBar.value : state
    // 动画触发完毕,主动触发resize事件
    setTimeout(() => {
      const resize = new Event('resize')
      window.dispatchEvent(resize)
    }, 300)
  }
  provide('triggerShowNavBar', triggerShowNavBar)
  provide('showNavBar', showNavBar)
  watchEffect(() => {
    triggerShowNavBar(!(route.meta.checkHome))
  })
  return showNavBar
}
